<template>
	<view>
		<view class="TUI-message-input-container">
			<!-- 快捷菜单栏 -->
			<!--      <view class="TUI-commom-function">
        <view v-for="(item, index) in commonFunction" :key="index" class="TUI-commom-function-item" :data-function="item" @tap="handleCommonFunctions">{{ item.name }}</view>
      </view> -->
			<view class="TUI-message-input flex items-center prow30">
				<!-- #ifndef H5 -->
				<image  style="display: block;margin-right: 16rpx" class="TUI-icon" @tap="switchAudio"
					:src="isAudio ? 'https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/keyboard.svg' : 'https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/audio.svg'">
				</image>
				<!-- #endif -->
				<view v-if="!isAudio" class="TUI-message-input-main">
					<textarea class="TUI-message-input-area" style="max-height: 100rpx;margin-top: 10rpx;" :adjust-position="true" :auto-height="true" :show-confirm-bar="false" cursor-spacing="20" v-model="inputText"
					 @input="onInputValueChange" @confirm="sendTextMessage" maxlength="-1" placeholder-class="input-placeholder"
					 placeholder="向Ta问候下吧~" @focus="inputBindFocus" @blur="inputBindBlur"
					 name="" id="" ></textarea>
					<!-- <input class="TUI-message-input-area" :adjust-position="true" confirm-type="send"  cursor-spacing="20" v-model="inputText"
						@input="onInputValueChange" @confirm="sendTextMessage" maxlength="140" type="text" placeholder-class="input-placeholder"
						placeholder="向Ta问候下吧~" @focus="inputBindFocus" @blur="inputBindBlur" /> -->
				</view>
				<view v-else class="TUI-message-input-main" @longpress="handleLongPress" @touchmove="handleTouchMove"
					@touchend="handleTouchEnd"
					style="display: flex; justify-content: center; font-size: 32rpx; font-family: PingFangSC-Regular">
					<text>{{ text }}</text>
				</view>
				<view class="TUI-message-input-functions" hover-class="none">
					<!-- <image class="TUI-icon" @tap="switchAudio"
						:src="isAudio ? 'https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/keyboard.svg' : 'https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/audio.svg'">
					</image> -->
					<image style="display: block;margin: 0 12rpx" class="TUI-icon" @tap="handleEmoji"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/face-emoji.svg"></image>

					<view v-if="sendMessageBtn" class="TUI-sendMessage-btn" @tap="sendTextMessage">发送</view>

					<image v-if="!sendMessageBtn" @tap="handleExtensions" style="display: block;" class="TUI-icon" src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/more.svg"></image>


				</view>
			</view>
			<view v-if="displayFlag === 'emoji'" class="TUI-Emoji-area">
				<TUI-Emoji @enterEmoji="appendMessage"></TUI-Emoji>
			</view>
			<view v-if="displayFlag === 'extension'" class="TUI-Extensions">
				<view class="TUI-Extension-slot" @tap="handleSendPicture">
					<image class="TUI-Extension-icon"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/take-photo.svg"></image>
					<view class="TUI-Extension-slot-name">拍摄照片</view>
				</view>
				<view class="TUI-Extension-slot" @tap="handleSendImage">
					<image class="TUI-Extension-icon"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/send-img.svg"></image>
					<view class="TUI-Extension-slot-name">发送图片</view>
				</view>
				<view class="TUI-Extension-slot" @tap="handleShootVideo">
					<image class="TUI-Extension-icon"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/take-video.svg"></image>
					<view class="TUI-Extension-slot-name">拍摄视频</view>
				</view>
				<view class="TUI-Extension-slot" @tap="handleSendVideo">
					<image class="TUI-Extension-icon"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/send-video.svg"></image>
					<view class="TUI-Extension-slot-name">发送视频</view>
				</view>
				<view class="TUI-Extension-slot" @tap="lishi_jilu">
					<image class="TUI-Extension-icon"
						src="https://static-1310167831.cos.ap-nanjing.myqcloud.com/uploads/20230615/c09a807bd8a4f8471c80879ce6ac99cc.png"></image>
					<view class="TUI-Extension-slot-name">历史消息</view>
				</view>
				<!-- <view class="TUI-Extension-slot" :data-value="1" @tap="handleCalling">
					<image class="TUI-Extension-icon"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/audio-calling.svg"></image>
					<view class="TUI-Extension-slot-name">语音通话</view>
				</view>
				<view class="TUI-Extension-slot" :data-value="2" @tap="handleCalling">
					<image class="TUI-Extension-icon"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/video-calling.svg"></image>
					<view class="TUI-Extension-slot-name">视频通话</view>
				</view>

				<view class="TUI-Extension-slot" @tap="handleServiceEvaluation">
					<image class="TUI-Extension-icon"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/service-assess.svg"></image>
					<view class="TUI-Extension-slot-name">服务评价</view>
				</view>
				<view class="TUI-Extension-slot" @tap="handleSendOrder">
					<image class="TUI-Extension-icon"
						src="https://jw-uniapp.oss-cn-beijing.aliyuncs.com/static/assets/send-order.svg"></image>
					<view class="TUI-Extension-slot-name">发送订单</view>
				</view> -->
			</view>
			<TUI-Common-Words class="tui-cards" :display="displayCommonWords" @sendMessage="$handleSendTextMessage"
				@close="$handleCloseCards"></TUI-Common-Words>
			<TUI-Order-List class="tui-cards" :display="displayOrderList" @sendCustomMessage="$handleSendCustomMessage"
				@close="$handleCloseCards"></TUI-Order-List>
			<TUI-Service-Evaluation class="tui-cards" :display="displayServiceEvaluation"
				@sendCustomMessage="$handleSendCustomMessage" @close="$handleCloseCards"></TUI-Service-Evaluation>
		</view>
		<view class="record-modal" v-if="popupToggle" @longpress="handleLongPress" @touchmove="handleTouchMove"
			@touchend="handleTouchEnd">
			<view class="wrapper">
				<view class="modal-loading"></view>
			</view>
			<view class="modal-title">
				{{ title }}
			</view>
		</view>
		permissionCameraContent="获取拍照权限是为了发送聊天图片" permissionAlbumContent="获取相册权限，是为了发送聊天图片" />
		<permissionModel ref="permissionModel" :permissionContent="permissionContent" />
		<model ref="model" :content="content" :openAppPermission="true" @toOpenAppPermission="toOpenAppPermission" />
	</view>
</template>

<script>
	import TUIEmoji from '../message-elements/emoji/index';
	import TUICommonWords from '../message-private/common-words/index';
	import TUIOrderList from '../message-private/order-list/index';
	import TUIServiceEvaluation from '../message-private/service-evaluation/index';

	export default {
		data() {
			return {
				permissionCameraContent:"获取拍照权限是为了发送聊天图片",
				permissionAlbumContent:"获取相册权限，是为了发送聊天图片",
				permissionCameraContent1:"获取拍照权限是为了发送聊天视频",
				permissionAlbumContent1:"获取相册权限，是为了发送聊天视频",
				permissionContent:'',
				content: '',
				content1: '发送图片需要打开相机的权限，请到应用设置里面开启。',
				content2: '发送图片需要打开相册的权限，请到应用设置里面开启。',
				content3: '录像需要打开相机的权限，请到应用设置里面开启。',
				content4: '发送视频需要打开相册的权限，请到应用设置里面开启。',
				uploadImg: '',
				inputText: '',
				extensionArea: false,
				sendMessageBtn: false,
				displayFlag: '',
				isAudio: false,
				bottomVal: 0,
				startPoint: 0,
				popupToggle: false,
				isRecording: false,
				canSend: true,
				text: '按住说话',
				title: ' ',
				notShow: false,
				isShow: true,
				recordTime: 0,
				recordTimer: null,
				commonFunction: [{
						name: '常用语',
						key: '0'
					},
					{
						name: '发送订单',
						key: '1'
					},
					{
						name: '服务评价',
						key: '2'
					}
				],
				displayServiceEvaluation: false,
				displayCommonWords: false,
				displayOrderList: false,
				jianpan:false
			};
		},

		components: {
			TUIEmoji,
			TUICommonWords,
			TUIOrderList,
			TUIServiceEvaluation
		},
		props: {
			conversation: {
				type: Object,
				default: () => {}
			}
		},

		beforeMount() {
			// 加载声音录制管理器
			this.recorderManager = uni.getRecorderManager();
			this.recorderManager.onStop(res => {
				clearInterval(this.recordTimer);
				// 兼容 uniapp 打包app，duration 和 fileSize 需要用户自己补充
				// 文件大小 ＝ (音频码率) x 时间长度(单位:秒) / 8
				let msg = {
					duration: res.duration ? res.duration : this.recordTime * 1000,
					tempFilePath: res.tempFilePath,
					fileSize: res.fileSize ? res.fileSize : ((48 * this.recordTime) / 8) * 1024
				};
				uni.hideLoading();
				// 兼容 uniapp 语音消息没有duration
				if (this.canSend) {
					let that=this
					if (msg.duration < 1000) {
						uni.showToast({
							title: '录音时间太短',
							icon: 'none'
						});
					} else {
						// res.tempFilePath 存储录音文件的临时路径
						// const message = uni.$TUIKit.createAudioMessage({
						// 	to: this.getToAccount(),
						// 	conversationType: this.conversation.type,
						// 	payload: {
						// 		file: msg
						// 	}
						// });
						// this.$sendTIMMessage(message);

						if(this.conversation.type==="C2C"){
							this.post1('api/im/im/send_msg',{
								user_id:uni.getStorageSync('user_id'),
								from_content:'[语音]',
								from_type:'TIMSoundElem'},false).then(res=>{
								console.log(res)
								if(res.code==1){
									const message = uni.$TUIKit.createAudioMessage({
										to: that.getToAccount(),
										conversationType: that.conversation.type,
										payload: {
											file: msg
										}
									});
									that.$sendTIMMessage(message);
								}else{
									uni.showToast({
										title: res.msg,
										icon: "none",
										duration: 1000
									})
								}
							})
						}else if(this.conversation.type==="GROUP"){
							this.post1('api/im/im/send_msg',{user_id:uni.getStorageSync('user_id'),from_content:'[语音]',from_type:'TIMSoundElem'},false).then(res=>{
								if(res.code==1){
									const message = uni.$TUIKit.createAudioMessage({
										to: that.getToAccount(),
										conversationType: that.conversation.type,
										payload: {
											file: msg
										}
									});
									that.$sendTIMMessage(message);
								}else{
									uni.showToast({
										title: res.msg,
										icon: "none",
										duration: 1000
									})
								}
							})
						}

					}
				}

				this.setData({
					startPoint: 0,
					popupToggle: false,
					isRecording: false,
					canSend: true,
					title: ' ',
					text: '按住说话'
				});
			});
		},

		methods: {
			switchAudio() {
				return
				this.setData({
					isAudio: !this.isAudio,
					text: '按住说话'
				});
			},

			handleLongPress(e) {
				this.recorderManager.start({
					duration: 60000,
					// 录音的时长，单位 ms，最大值 600000（10 分钟）
					sampleRate: 44100,
					// 采样率
					numberOfChannels: 1,
					// 录音通道数
					encodeBitRate: 192000,
					// 编码码率
					format: 'aac' // 音频格式，选择此格式创建的音频消息，可以在即时通信 IM 全平台（Android、iOS、微信小程序和Web）互通
				});
				this.setData({
					startPoint: e.touches[0],
					title: '正在录音',
					// isRecording : true,
					// canSend: true,
					notShow: true,
					isShow: false,
					isRecording: true,
					popupToggle: true,
					recordTime: 0
				});
				this.recordTimer = setInterval(() => {
					this.recordTime++;
				}, 1000);
			},

			// 录音时的手势上划移动距离对应文案变化
			handleTouchMove(e) {
				if (this.isRecording) {
					if (this.startPoint.clientY - e.touches[e.touches.length - 1].clientY > 100) {
						this.setData({
							text: '抬起停止',
							title: '松开手指，取消发送',
							canSend: false
						});
					} else if (this.startPoint.clientY - e.touches[e.touches.length - 1].clientY > 20) {
						this.setData({
							text: '抬起停止',
							title: '上划可取消',
							canSend: true
						});
					} else {
						this.setData({
							text: '抬起停止',
							title: '正在录音',
							canSend: true
						});
					}
				}
			},

			// 手指离开页面滑动
			handleTouchEnd() {
				this.setData({
					isRecording: false,
					popupToggle: false
				});
				uni.hideLoading();
				this.recorderManager.stop();
			},
			handleEmoji() {
				let targetFlag = 'emoji';

				if (this.displayFlag === 'emoji') {
					targetFlag = '';
				}

				this.setData({
					displayFlag: targetFlag
				});
			},

			handleExtensions() {
				let targetFlag = 'extension';

				if (this.displayFlag === 'extension') {
					targetFlag = '';
				}

				this.setData({
					displayFlag: targetFlag
				});
			},

			error(e) {
				console.log(e.detail);
			},

			toOpenAppPermission() {
				this.$refs.permissionModel.close()
			},
			handleSendPicture() {
				console.log('%c [ handleSendPicture ]-375', 'font-size:13px; background:pink; color:#bf2c9f;', this.conversation.type);
				this.$refs.uploadImg.openAppPermissionAndUploadCameraImage()
				// #ifdef APP-PLUS
				this.androidCameraPermission('camera', this.content1, this.permissionCameraContent)
				// #endif
				// this.sendImageMessage('camera');
			},
			handleSendImage() {
				console.log('%c [ handleSendImage ]-447', 'font-size:13px; background:pink; color:#bf2c9f;', this.conversation.type)
				// openAppPermissionAndUploadAlbum
				this.$refs.uploadImg.openAppPermissionAndUploadAlbumImage()
				// #ifdef APP-PLUS
				this.androidCameraPermission('album', this.content2, this.permissionAlbumContent)
				// #endif
				// this.sendImageMessage('album');
			},
			androidCameraPermission(type, content, permissionContent) {
				console.log('%c [ type ]-101', 'font-size:13px; background:pink; color:#bf2c9f;', type)
				let options = {
					'camera': 'android.permission.CAMERA',
					'album': 'android.permission.WRITE_EXTERNAL_STORAGE'
				}
				let permission = options[type]
				// let permission = type === 'camera' ? 'CAMERA' : 'READ_EXTERNAL_STORAGE'
				console.log('%c [ permission ]-93', 'font-size:13px; background:pink; color:#bf2c9f;', permission)
				var Manifest = plus.android.importClass("android.Manifest");
				var MainActivity = plus.android.runtimeMainActivity();
				let result = MainActivity.checkSelfPermission(Manifest.permission[permission]);
				console.log('%c [ result ]-63', 'font-size:13px; background:pink; color:#bf2c9f;', result)
				if (result) {
					plus.android.requestPermissions([permission], e => {
						console.log('%c [ e ]-70', 'font-size:13px; background:pink; color:#bf2c9f;', e)
						if (e.deniedAlways.length > 0) { // 权限被拒绝或永久拒绝就给提示
							this.content = content
							this.$refs.model.open()
							this.$refs.permissionModel.close()
						} else if (e.deniedPresent.length > 0) {
							this.$refs.permissionModel.close()
						} else if (e.granted.length > 0) {
							this.$refs.permissionModel.close(); // 别忘了关闭提示
							if (type == 'camera') {
								// this.uploadCamera(); // 同意则调用方法
							} else if (type == 'album') {
								// this.uploadAlbum(); // 同意则调用方法
							}
						}
					})
					// this.uploadCamera(); // 有权限则直接调用方法
				} else {
					// this.uploadCamera()
					this.permissionContent = permissionContent
					this.$refs.permissionModel.open()
					// this.permissionContent = ''
					plus.android.requestPermissions([permission], e => {
						console.log('%c [ e ]-70', 'font-size:13px; background:pink; color:#bf2c9f;', e)
						if (e.deniedAlways.length > 0) { // 权限被拒绝或永久拒绝就给提示
							this.content = content
							this.$refs.permissionModel.close()
							this.$refs.model.open()
						} else if (e.deniedPresent.length > 0) {
							this.$refs.permissionModel.close()
						} else if (e.granted.length > 0) {
							this.$refs.permissionModel.close(); // 别忘了关闭提示
							if (type == 'camera') {
								// this.uploadCamera(); // 同意则调用方法
							} else if (type == 'album') {
								// this.uploadAlbum(); // 同意则调用方法
							}
						}
					})
				}
			},
			uploadImageSuccess(url,res) {
				console.log('%c [ res ]-457', 'font-size:13px; background:pink; color:#bf2c9f;', res)
				console.log('%c [ url ]-456', 'font-size:13px; background:pink; color:#bf2c9f;', url)
				let that=this
				let c=url
				if(that.conversation.type==="C2C"){
					that.post1('api/im/im/send_friend_msg',{
						friend_id:uni.getStorageSync('friend_id'),
						from_content:c,
						from_type:'TIMImageElem'},false).then(re=>{
						console.log(re)
						if(re.code==1){
							const message = uni.$TUIKit.createImageMessage({
								to: that.getToAccount(),
								conversationType: that.conversation.type,
								payload: {
									file: res
								},
								onProgress: percent => {
									message.percent = percent;
								}
							});
							uni.hideLoading()
							that.$sendTIMMessage(message);
						}else{
							uni.hideLoading()
							uni.showToast({
								title: re.msg,
								icon: "none",
								duration: 1000
							})
						}
					})
				}else if(that.conversation.type==="GROUP"){
					that.post1('api/im/im/send_group_msg',{
						group_id:uni.getStorageSync('group_id'),
						content:c,
						content_type:'TIMImageElem'},false).then(re=>{
						if(re.code==1){
							const message = uni.$TUIKit.createImageMessage({
								to: that.getToAccount(),
								conversationType: that.conversation.type,
								payload: {
									file: res
								},
								onProgress: percent => {
									message.percent = percent;
								}
							});

							that.$sendTIMMessage(message);
						}else{
							uni.showToast({
								title: re.msg,
								icon: "none",
								duration: 1000
							})
						}
						uni.hideLoading()
					})
				}
			},
			uploadVideoSuccess(url,res) {
				let that=this
				let c=url
				if(that.conversation.type==="C2C"){
					that.post1('api/im/im/send_friend_msg',{
						friend_id:uni.getStorageSync('friend_id'),
						from_content:c,
						from_type:'TIMVideoFileElem'},false).then(re=>{
						console.log(re)
						if(re.code==1){
							const message = uni.$TUIKit.createVideoMessage({
								to: this.getToAccount(),
								conversationType: this.conversation.type,
								payload: {
									file: res
								},
								onProgress: percent => {
									message.percent = percent;
								}
							});
							uni.hideLoading()
							this.$sendTIMMessage(message);
						}else{
							uni.hideLoading()
							uni.showToast({
								title: re.msg,
								icon: "none",
								duration: 1000
							})
						}
					})
				}else if(that.conversation.type==="GROUP"){
					that.post1('api/im/im/send_group_msg',{
						group_id:uni.getStorageSync('group_id'),
						content:c,
						content_type:'TIMVideoFileElem'},false).then(re=>{
						if(re.code==1){
							const message = uni.$TUIKit.createVideoMessage({
								to: this.getToAccount(),
								conversationType: this.conversation.type,
								payload: {
									file: res
								},
								onProgress: percent => {
									message.percent = percent;
								}
							});
							uni.hideLoading()
							this.$sendTIMMessage(message);
						}else{
							uni.hideLoading()
							uni.showToast({
								title: re.msg,
								icon: "none",
								duration: 1000
							})
						}
					})
				}
			},
			handleShootVideo() {
				// #ifdef APP-PLUS
				this.androidCameraPermission('camera', this.content3, this.permissionCameraContent1)
				// #endif
				this.$refs.uploadImg.openAppPermissionAndUploadCameraVideo()
				// this.sendVideoMessage('camera');
			},
			handleSendVideo() {
				console.log('%c [ handleSendVideo ]-612', 'font-size:13px; background:pink; color:#bf2c9f;', 'handleSendVideo')
				// #ifdef APP-PLUS
				this.androidCameraPermission('album', this.content4, this.permissionAlbumContent1)
				// #endif
				this.$refs.uploadImg.openAppPermissionAndUploadAlbumVideo()
			},
			sendVideoMessage(type) {
				let that=this
				uni.chooseVideo({
					sourceType: [type],
					// 来源相册或者拍摄
					maxDuration: 60,
					// 设置最长时间60s
					camera: 'back',
					// 后置摄像头
					success: res => {
						uni.showLoading({
							title: ''
						})
						if (res) {
							console.log(res,11111222233333)
							uni.uploadFile({
								url: that.BASE_URL+'addons/cos/index/uploads', //仅为示例，非真实的接口地址
								filePath: res.tempFilePath,
								name: 'file',
								header:{
									token:uni.getStorageSync('token')
								},
								success: (a) => {
									console.log(JSON.parse(a.data))
									let c=JSON.parse(a.data).data.fullurl
									if(that.conversation.type==="C2C"){
										that.post1('api/im/im/send_friend_msg',{
											friend_id:uni.getStorageSync('friend_id'),
											from_content:c,
											from_type:'TIMVideoFileElem'},false).then(re=>{
											console.log(re)
											if(re.code==1){
												const message = uni.$TUIKit.createVideoMessage({
													to: this.getToAccount(),
													conversationType: this.conversation.type,
													payload: {
														file: res
													},
													onProgress: percent => {
														message.percent = percent;
													}
												});
												uni.hideLoading()
												this.$sendTIMMessage(message);
											}else{
												uni.hideLoading()
												uni.showToast({
													title: re.msg,
													icon: "none",
													duration: 1000
												})
											}
										})
									}else if(that.conversation.type==="GROUP"){
										that.post1('api/im/im/send_group_msg',{
											group_id:uni.getStorageSync('group_id'),
											content:c,
											content_type:'TIMVideoFileElem'},false).then(re=>{
											if(re.code==1){
												const message = uni.$TUIKit.createVideoMessage({
													to: this.getToAccount(),
													conversationType: this.conversation.type,
													payload: {
														file: res
													},
													onProgress: percent => {
														message.percent = percent;
													}
												});
												uni.hideLoading()
												this.$sendTIMMessage(message);
											}else{
												uni.hideLoading()
												uni.showToast({
													title: re.msg,
													icon: "none",
													duration: 1000
												})
											}
										})
									}
								}
							})
						}
					}
				});
			},

			handleCommonFunctions(e) {
				switch (e.target.dataset.function.key) {
					case '0':
						this.setData({
							displayCommonWords: true
						});
						break;

					case '1':
						this.setData({
							displayOrderList: true
						});
						break;

					case '2':
						this.setData({
							displayServiceEvaluation: true
						});
						break;

					default:
						break;
				}
			},

			handleSendOrder() {
				this.setData({
					displayOrderList: true
				});
			},

			appendMessage(e) {
				this.setData({
					inputText: this.inputText + e.detail.message,
					sendMessageBtn: true
				});
			},

			getToAccount() {
				if (!this.conversation || !this.conversation.conversationID) {
					return '';
				}

				switch (this.conversation.type) {
					case 'C2C':
						return this.conversation.conversationID.replace('C2C', '');

					case 'GROUP':
						return this.conversation.conversationID.replace('GROUP', '');

					default:
						return this.conversation.conversationID;
				}
			},

			handleCalling(e) {
				if (this.conversation.type === 'GROUP') {
					uni.navigateTo({
						url: '/im/group/invitation-friends/conversation?groupID=' + this.conversation.conversationID +
							'&callMediaType=' + e.currentTarget.dataset.value
					});
					return;
				}

				const type = e.currentTarget.dataset.value;
				const {
					userID
				} = this.conversation.userProfile;
				this.$emit('handleCall', {
					detail: {
						type,
						userID
					}
				});
				this.displayFlag = '';
			},

			sendTextMessage(msg, flag) {
				let that=this
				this.jianpan=true
				if(this.conversation.type==="C2C"){
					this.post1('api/im/im/send_msg',{
						user_id:uni.getStorageSync('user_id'),
						from_content:that.inputText,
						from_type:'TIMTextElem'},false).then(res=>{
						console.log(res)
						if(res.code==1){
							const to = that.getToAccount();
							const text = flag ? msg : that.inputText;
							const message = uni.$TUIKit.createTextMessage({
								to,
								conversationType: that.conversation.type,
								payload: {
									text
								}
							});
							that.setData({
								inputText: '',
								sendMessageBtn: false
							});
							that.$sendTIMMessage(message);
						}else{
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 1000
							})
						}
					})
				}else if(this.conversation.type==="GROUP"){
					this.post1('api/im/im/send_msg',{user_id:uni.getStorageSync('user_id'),from_content:that.inputText,from_type:'TIMTextElem'},false).then(res=>{
						if(res.code==1){
							const to = that.getToAccount();
							const text = flag ? msg : that.inputText;
							const message = uni.$TUIKit.createTextMessage({
								to,
								conversationType: that.conversation.type,
								payload: {
									text
								}
							});
							that.setData({
								inputText: '',
								sendMessageBtn: false
							});
							that.$sendTIMMessage(message);
						}else{
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 1000
							})
						}
					})
				}


			},
			lishi_jilu:function(){
				if(this.conversation.type==="C2C"){
					this.displayFlag =''
					uni.navigateTo({
						url:'/fenbao/pages/wenzhang/liaotian'
					})
				}else if(this.conversation.type==="GROUP"){
					this.displayFlag =''
					uni.navigateTo({
						url:'/fenbao/pages/wenzhang/liaotian1?room_id='+this.conversation.conversationID.slice(5,-1)
					})
				}

			},

			onInputValueChange(event) {
				if (event.detail.value) {
					this.setData({
						sendMessageBtn: true
					});
				} else {
					this.setData({
						sendMessageBtn: false
					});
				}
			},

			$handleSendTextMessage(event) {
				this.sendTextMessage(event.detail.message, true);
				this.setData({
					displayCommonWords: false
				});
			},

			$handleSendCustomMessage(e) {
				const message = uni.$TUIKit.createCustomMessage({
					to: this.getToAccount(),
					conversationType: this.conversation.type,
					payload: e.detail.payload
				});
				this.$sendTIMMessage(message);
				this.setData({
					displayOrderList: false
				});
			},

			$handleCloseCards(e) {
				switch (e.detail.key) {
					case '0':
						this.setData({
							displayCommonWords: false
						});
						break;

					case '1':
						this.setData({
							displayOrderList: false
						});
						break;

					case '2':
						this.setData({
							displayServiceEvaluation: false
						});
						break;

					default:
						break;
				}
			},

			$sendTIMMessage(message) {
				this.$emit('sendMessage', {
					detail: {
						message
					}
				});
				uni.$TUIKit.sendMessage(message);
				this.setData({
					displayFlag: ''
				});
			},

			handleClose() {
				this.setData({
					displayFlag: ''
				});
			},

			handleServiceEvaluation() {
				this.setData({
					displayServiceEvaluation: true
				});
			},

			inputBindFocus() {
				// this.jianpan=true
				console.log('占位：函数 inputBindFocus 未声明');
			},

			inputBindBlur() {
				console.log('占位：函数 inputBindBlur 未声明');
			}
		}
	};
</script>
<style>
@import '../message-input/index.css';
</style>